<?php

namespace app\api\model;

use think\Model;

/**
 * token模型
 */
class Token extends Model
{

    protected $name='user_token';

    // 开启自动写入时间戳字段
    protected $auto_timestamp = 'false';

    
    public function setToken($token, $uid, $type) {
 
        $is_exit = $this->where('user_id', $uid)->where('type', $type)->find();
        if ($is_exit) {
            $rst = $this->where('user_id', $uid)->where('type', $type)->update(['token' => $token]);
        } else {
            $rst = $this->save(['user_id' => $uid, 'type' => $type, 'token' => $token]);
        }
   
        return $rst;
     }


}
